#pragma once
#include "AnyEditor.h"
#include "ShapeReps.h"
#include <deque>

class CEditorHelper;
class CAnyDocument;

class GEOMDBAPI CModelEditor :
	public CAnyEditor
{
public:

	CModelEditor(void);
	virtual ~CModelEditor(void) = 0;

	TDF_Label NewLabel(const TCollection_ExtendedString& szName);
	void AddSubEditor(CEditorHelper* pEditor, UINT nStep);
	// must be called by child
	virtual void Initialize(CAnyView* pView);
	virtual void Destroy();
	virtual void Preview();
	virtual void Abort();
	virtual void Finish();
	// mouse message
	virtual EditorState OnLButtonDown(UINT nFlags, long x, long y);
	virtual EditorState OnLButtonUp(UINT nFlags, long x, long y);
	virtual void OnMouseMove(UINT nFlags, long x, long y);

	int CurrentStep();
protected:
	//
	virtual bool CreatePreviewShape(void) = 0;
	virtual bool CreateShapeLabel(TDF_Label& label)=0;

	virtual bool OnAddShape(TDF_Label& shapeLabel, CAnyDocument* pADoc);

	void SetPreviewShape(const TopoDS_Shape& shape);

private:
	bool	m_bStart;
	CEditorHelper*  m_pEditorCur;
	std::deque<CEditorHelper*> m_EditorPtrs;
	// display temporary
	CShapeReps m_ShapeRep;
};

//////////////////////////////////////////////////////////////////////////
template<typename TFunctionDriver, typename TFunctionDriverHandle>
bool ProcessFunctionDriver(TDF_Label& label, TFunctionDriverHandle& functionDriver)
{
	Handle(TFunction_Function) myFunction = TFunction_Function::Set(label, TFunctionDriver::GetID());
	if(!TFunction_DriverTable::Get()->FindDriver(TFunctionDriver::GetID(), functionDriver)) 
		return false;

	functionDriver->Init(label);
	TFunction_Logbook log;
	if(functionDriver->Execute(log))// not zero, then failed
		return false; // failed

	return true;
}